package com.njtoyo.taxi.admin.rest.controller.business.driver;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mongo.entity.secondary.AdminDeductDriverMoneyLogMongo;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.MoneyDeductingPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.MoneyDeductingCreateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.MoneyDeductingLogQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.MoneyDeductingQueryWrapper;
import com.njtoyo.taxi.admin.service.business.driver.DriverMoneyDeductingService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("business/driver")
@Api(tags = {"司机扣款"})
public class DriverMoneyDeductingController {

    @Autowired
    private DriverMoneyDeductingService driverMoneyDeductingService;

    @GetMapping("/money_deducting")
    @ApiOperation(value = "司机扣款列表", notes = "司机扣款列表，权限：driver_money_deducting_list")
    @PermissionScope(names = {"driver_money_deducting_list"})
    RestResult<Page<MoneyDeductingPresenter>> moneyDeducting(@ModelAttribute("admin") AdminUser adminUser, @Valid MoneyDeductingQueryWrapper wrapper) {
        return driverMoneyDeductingService.getMoneyDeductingList(adminUser, wrapper);
    }

    @GetMapping("/money_deducting/{id}")
    @ApiOperation(value = "司机扣款详情", notes = "司机扣款详情，权限：driver_money_deducting_detail")
    @PermissionScope(names = {"driver_money_deducting_detail"})
    RestResult<MoneyDeductingPresenter> moneyDeducting(@PathVariable("id") Long id) {
        return driverMoneyDeductingService.getMoneyDeducting(id);
    }

    @PostMapping("/money_deducting")
    @ApiOperation(value = "司机扣款", notes = "司机扣款，权限：driver_money_deducting")
    @PermissionScope(names = {"driver_money_deducting"})
    RestResult moneyDeducting(@ModelAttribute("admin") AdminUser adminUser, @RequestBody MoneyDeductingCreateWrapper wrapper) {
        return driverMoneyDeductingService.moneyDeducting(adminUser, wrapper);
    }

    @GetMapping("/money_deducting_log")
    @ApiOperation(value = "司机扣款的管理员操作日志", notes = "司机扣款的管理员操作日志，权限：driver_money_deducting_log")
    @PermissionScope(names = {"driver_money_deducting_log"})
    RestResult<PageImpl<AdminDeductDriverMoneyLogMongo>> moneyDeductingLog(MoneyDeductingLogQueryWrapper wrapper) {
        return driverMoneyDeductingService.moneyDeductingLog(wrapper);
    }

}
